<template>
  <div class="reserveBed-container">
    <el-col :span="4">
      <reserveStructure
        @changeFloor="changeFloor"
      />
    </el-col>
    <el-col :span="2"></el-col>
    <el-col :span="18">
      <reserveRoomBed :flId="flId" @reserve="reserve"  />
    </el-col>
  </div>
</template>

<script type="text/ecmascript-6">
  import reserveStructure from '../../components/room/reserveStructure.vue'
  import reserveRoomBed from '../../components/room/reserveRoomBed.vue'
  import checkInApi from '../../service/member/checkInApi'
  import commonApi from '../../service/member/commonApi';

  export default {
    data() {
      return {
        flId: null
      }
    },
    props:["currentTasId","member"],
    methods: {
      changeFloor(flId) {
        if(flId) {
          this.flId = flId;
        }
      },
      reserve(bedId){
        let self = this;
        var form = {actId:this.member.actId,bedId:bedId,memberId:this.member.memberId,runId:this.member.runId,tasId:this.currentTasId};
        checkInApi.bedAppointment(form).then(res => {
          if(res.body.status==200){
            self.$message.info('预约成功!');
            commonApi.getFlowRouter("inApply",this.member.actId,"save").then(function(response){
              //save代表保存，空值代表下一步
              if(response.body.status==200){
                if(response.body.data.routerKey=='memberCheckIn'){
                  self.$router.push({name:"memberCheckIn"});
                }else{
                  if(self.member.taskKeyArr.length==1){
                    self.$emit("goto",self.member.taskKeyArr[0]);
                  }else{
                    //获取当前任务在数组中的位置
                    if(self.member.taskKeyArr.indexOf("inApply_examination")>=0){
                      self.$emit("goto","inApply_examination");
                    }else if(self.member.taskKeyArr.indexOf("inApply_InAssessment")>=0){
                      self.$emit("goto","inApply_InAssessment");
                    }else if(self.member.taskKeyArr.indexOf("inApply_servicePlan")>=0){
                      self.$emit("goto","inApply_servicePlan");
                    }
                  }
                }
              }
            });
          }else{
            this.$message.info(res.body.message);
          }
        },function(res){
          alert(res.data.message);
        });
      }
    },
    mounted: function () {
    },
    components: {reserveStructure, reserveRoomBed}
  }
</script>
<style>
  .el-col-2{
    height: 1px;
  }
</style>
